

import type { FormRules } from 'element-plus'
import type { ruleFormType } from './type'
import { reactive } from 'vue'

// 校验规则


// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default function (ruleForm: ruleFormType) {

  const rules = reactive<FormRules<typeof ruleForm>>({
    username: [{ validator: validateUsername, trigger: 'blur' }],
    password: [{ validator: validatePass, trigger: 'blur' }],

  })



  function validateUsername(rule: any, value: any, callback: any) {


    if (value === '') {
      return callback(new Error('请输入用户名'))
    }


    if (value.length < 2 || value.length >= 10) {
      return callback(new Error('长度不对 需要2-10'))
    }
    callback()

  }
  function validatePass(rule: any, value: any, callback: any) {


    if (value === '') {
      return callback(new Error('请输入密码'))
    }

    console.log(value);

    if (!/^\w{6,12}$/.test(value)) {
      return callback(new Error('密码需要6-12数字字母下划线'))
    }

    callback()

  }


  return {
    rules
  }

}
